package com.wl.week_01.Producer_Consumer;

/**
 * 生产者进程
 * @author TaiZai
 * @data 2024/9/30 16:20
 */
public class ProducerThread implements Runnable {

    @Override
    public void run() {
        while (true) {
            if (Product_House.getProducts().size() >= Product_House.MAX_PRODUCTS) {
                System.out.println("仓库已满，无法再生产");
            } else {
                Product_House.put(new Product("产品"));
                System.out.println("Producer 生产了一个产品，剩余: " + Product_House.getProducts().size() + " 个");
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
